package com.sky.controller.admin;


import com.github.pagehelper.Page;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/dish")
@Api(tags = "菜品相关的接口")
@Slf4j
public class DishController {

    @Autowired
    private  DishService dishService;

    @PostMapping//如果为空就不要添加括号了
    @ApiOperation("新增菜品")
    public Result save(@RequestBody DishDTO dishDTO){
        log.info("新增菜品:",dishDTO);
        dishService.save(dishDTO);
        return Result.success();
    }
    @GetMapping("/page")
    @ApiOperation("菜品的分页查询")
    public Result<PageResult> pageQueryDish(DishPageQueryDTO dishPageQueryDTO){
        log.info("菜品的分类查询：",dishPageQueryDTO);
        PageResult pageResult=dishService.pageQueryDish(dishPageQueryDTO);//将查询结果封装到dishVOS
        return Result.success(pageResult);
    }

    /**
     * 删除菜品
     * @param ids
     * @return
     */
    @DeleteMapping
    public Result delete(@RequestParam List<Long> ids){
        log.info("删除菜品：",ids);
        dishService.delete(ids);
        return Result.success();
    }

    /**
     * 查询菜品信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("查询菜品信息")
    public Result<DishVO> find(@PathVariable Long id){
      log.info("查询菜品信息");
       DishVO dishVO=dishService.selectById(id);
       return Result.success(dishVO);
    }

    /**
     * 修改菜品信息
     * @param dishDTO
     * @return
     */
    @PutMapping
    @ApiOperation("修改菜品信息")
    public Result update(@RequestBody DishDTO dishDTO){
        log.info("修改菜品信息");
        dishService.updateDish(dishDTO);
        return Result.success();
    }


}
